<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    ul li {
        width: 100px;
        height: 100px;
        border: 1px solid #ccc;
        float: left;
        box-sizing: border-box;
        line-height: 100px;
        text-align: center;
    }

    ul {
        width: 700px;
    }

    .wrap {
        width: 700px;
        margin: auto
    }
</style>

<body>
    <div class="wrap">
        <ul>
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li>6</li>
            <li>天</li>
        </ul>

        <ul id="ul">

        </ul>

    </div>

    <script>
        var ul = document.getElementById("ul")


        var time = new Date(2019, 7, 22)

        var year = time.getFullYear()
        var month = time.getMonth()
        var date = time.getDate()

        // 获取本月最后一天
        var lastDate = new Date(year, month + 1, 0).getDate()
        // 获取上个月最后一天星期几
        var preLastDay = new Date(year, month, 0).getDay()
        var preLastDate = new Date(year, month, 0).getDate()

        var preFirstDate = preLastDate - preLastDay + 1

        html = ''


        for (var i = 1; i <= preLastDay; i++) {
            html += `<li>${preFirstDate++}</li>`
        }
        for (var i = 1; i <= lastDate; i++) {
            html += `<li>${i}</li>`
        }

        for (var i = 1; i <= 42 - preLastDay - lastDate; i++) {
            html += `<li>${i}</li>`
        }

        ul.innerHTML = html




        // var str = "123"

        // console.log(str.replace("1", "3"))

        // console.log(str)
        // [0 - 2]
        // Math.floor(Math.random() * arrs.length)


        // function fn(str) {
        //     var start = str[0].toUpperCase()
        //     var end = str[str.length - 1].toUpperCase()
        //     return start + str.slice(1, str.length - 2) + end

        // }

        // console.log(fn("qwrwertfe"))


    </script>
</body>

</html>